package c_processPkg

import (
	"Infinichat_mixed/entity"
	"fmt"
	"net"
)

type CurUser_ struct {
	Conn net.Conn
	entity.User
}

var OnlineUsers = make(map[uint]*entity.User, 1000)
var CurUser CurUser_

func outputOnlineUser() {
	for id, user := range OnlineUsers {
		if user.UserStatus == entity.UserOnline {
			fmt.Printf("id:%d\t user:%v\n", id, user)
		}
	}
}

func updateUserStatus(notifyUserStatusMes *entity.NotifyUserStatusMes) {
	if notifyUserStatusMes.Status == entity.UserOnline {
		fmt.Printf("user: %d online!\n", notifyUserStatusMes.UserId)
	} else if notifyUserStatusMes.Status == entity.UserOffline {
		fmt.Printf("user: %d offline!\n", notifyUserStatusMes.UserId)
		// 这里需要从OnlineUsers中移除
		delete(OnlineUsers, notifyUserStatusMes.UserId)
	}
	user, ok := OnlineUsers[notifyUserStatusMes.UserId]
	if !ok {
		user = &entity.User{}
		user.ID = notifyUserStatusMes.UserId
	}
	user.UserStatus = notifyUserStatusMes.Status
	OnlineUsers[notifyUserStatusMes.UserId] = user

}
